/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ssau.model.storing.factories;

import java.util.Properties;
import ru.ssau.model.storing.DataAccessException;
import ru.ssau.model.storing.ForumDataAccessObject;
import ru.ssau.model.storing.ForumDatabaseDAO;


public class ForumDatabaseDAOFactory extends ForumDAOFactory {

    private ForumDatabaseDAO databaseDAO = null;

    private String host;
    private String port;
    private String dbName;
    private String user;
    private String password;

    public ForumDatabaseDAOFactory(Properties settings) {
        host = settings.getProperty("host");
        port = settings.getProperty("port");
        dbName = settings.getProperty("dbname");
        user = settings.getProperty("user");
        password = settings.getProperty("password");
    }

    @Override
    public ForumDataAccessObject getDAO() throws DataAccessException {
        if(databaseDAO == null) {
            databaseDAO = new ForumDatabaseDAO(host, port, dbName, user, password);
        }
        return databaseDAO;
    }

}
